﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RN.ERP.Web.ModelService;
using RN.ERP.Web.EnterpriseService;
using Newtonsoft.Json;
using Fly.Common.Linq;
using Fly.Common.WorkFlow;
using Telerik.Web.UI;
using Telerik.Web.UI.Skins;
using System.Configuration;

namespace RN.ERP.Web.Enterprise
{
    public partial class EnterpriseFinancialInfoListAudit : BasePage
    {
        public override bool IsCheckPermission
        {
            get
            {
                return false;
            }
        }
        protected string AreaCode
        {
            get
            {
                return UserInfo.CurrentArea;
            }
        }
        protected string RoleId
        {
            get
            {
                return UserInfo.RoleId;
            }
        }

        private EnterpriseService.EnterpriseServiceClient enterpriseServiceClient = new EnterpriseService.EnterpriseServiceClient();
        private BasicService.BasicServiceClient basicServiceClient = new BasicService.BasicServiceClient();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
            }
        }

        /// <summary>
        /// 客户端grid刷新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            if (e.Argument == "Rebind")
            {
                ListFinancial.MasterTableView.SortExpressions.Clear();
                ListFinancial.MasterTableView.GroupByExpressions.Clear();
                ListFinancial.Rebind();
            }

        }
        protected void ListFinancial_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            FinancialDataBind();
        }

        private void FinancialDataBind()
        {
            int pageIndex = ListFinancial.CurrentPageIndex;
            int pageSize = ListFinancial.PageSize;
            int count;
            Guid corpGuid = Guid.Empty;
            int? currentYear;
            currentYear = Convert.ToInt32(ddlYear.SelectedValue);
            if (currentYear == -1)
            {
                currentYear = null;
            }
            string areaCode = UserInfo.AreaCode;
            string corpName = txtCorpName.Text.Trim(); 

            var result = enterpriseServiceClient.GetCorpFinancialInfoList(out count, corpName, pageIndex, pageSize, corpGuid, currentYear, areaCode);
            var MachineInfolist = JsonConvert.DeserializeObject<IList<tb_corp_FinancialInfo>>(result);
            ListFinancial.AllowCustomPaging = true;
            ListFinancial.VirtualItemCount = count;
            ListFinancial.DataSource = MachineInfolist;
        }
        
        protected void ddlYear_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            FinancialDataBind();
            ListFinancial.Rebind();
        }
    }
}